﻿namespace SimbaRGVMonitor.Models
{
    class Robot
    {
        public Robot(
            string robotNo, string moveStatus,
            double px, double py, string currentVertex,
            double yaw, string taskAction, string taskStatus, int packetState)
        {
            this.px = px;
            this.py = py;
            this.yaw = yaw;
            this.robotNo = robotNo;
            this.moveStatus = moveStatus;
            this.taskAction = taskAction;
            this.taskStatus = taskStatus;
            this.packetState = packetState;
            this.currentVertex = currentVertex;
        }

        //====================================================================================================
        //以上是类型构造函数
        //----------------------------------------------------------------------------------------------------
        //以下是类型字段
        //====================================================================================================

        private readonly string robotNo;
        private readonly string moveStatus;
        private readonly double px;
        private readonly double py;
        private readonly string currentVertex;
        private readonly double yaw;
        private readonly string taskAction;
        private readonly string taskStatus;
        private readonly int packetState;

        //====================================================================================================
        //以上是类型字段
        //----------------------------------------------------------------------------------------------------
        //以下是类型属性
        //====================================================================================================

        public string RobotNo
        {
            get { return robotNo; }
        }

        public string MoveStatus
        {
            get { return moveStatus; }
        }

        public double Px
        {
            get { return px; }
        }

        public double Py
        {
            get { return py; }
        }

        public string CurrentVertex
        {
            get { return currentVertex; }
        }

        public double Yaw
        {
            get { return yaw; }
        }

        public string TaskAction
        {
            get { return taskAction; }
        }

        public string TaskStatus
        {
            get { return taskStatus; }
        }

        public int PacketState
        {
            get { return packetState; }
        }

        //====================================================================================================
        //以上是类型属性
        //----------------------------------------------------------------------------------------------------
        //以下是重载操作符==及!=
        //====================================================================================================

        public static bool operator ==(Robot left, Robot right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(Robot left, Robot right)
        {
            return Equals(left, right) == false;
        }

        //====================================================================================================
        //以上是重载操作符==及!=
        //----------------------------------------------------------------------------------------------------
        //以下是重写Equals及GetHashCode
        //====================================================================================================

        public override bool Equals(object obj)
        {
            var other = obj as Robot;
            return other != null &&
                other.robotNo == robotNo &&
                other.moveStatus == moveStatus &&
                other.px == px &&
                other.py == py &&
                other.currentVertex == currentVertex &&
                other.yaw == yaw &&
                other.taskAction == taskAction &&
                other.packetState == packetState;
        }

        public override int GetHashCode()
        {
            var hashCode = robotNo == null ? string.Empty.GetHashCode() : robotNo.GetHashCode();
            hashCode ^= moveStatus == null ? string.Empty.GetHashCode() : moveStatus.GetHashCode();
            hashCode ^= px.GetHashCode();
            hashCode ^= py.GetHashCode();
            hashCode ^= currentVertex == null ? string.Empty.GetHashCode() : currentVertex.GetHashCode();
            hashCode ^= yaw.GetHashCode();
            hashCode ^= taskAction == null ? string.Empty.GetHashCode() : taskAction.GetHashCode();
            hashCode ^= packetState.GetHashCode();
            return hashCode;
        }
    }
}
